//
//  ZYSecondVC.m
//  YiLin
//
//  Created by Zyark on 2018/5/30.
//  Copyright © 2018年 Zyark. All rights reserved.
//

#import "ZYSecondVC.h"

@interface ZYSecondVC ()
@property(nonatomic,strong) UIButton *button;
@end

@implementation ZYSecondVC

- (void)viewDidLoad {
    [super viewDidLoad];
    _navigationView = [[ZYNavigationView alloc] initWithFrame:CGRectMake(0, 0, ZYSCREEN_W, GetRectNavAndStatusHight + 20)];
    [self.view addSubview:_navigationView];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}


- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [self setupLeftButton];
    self.navigationController.navigationBar.titleTextAttributes=@{NSForegroundColorAttributeName:[UIColor whiteColor]};
     self.tabBarController.tabBar.hidden = YES;
}

-(void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    self.tabBarController.tabBar.hidden = NO;
    [self.button removeFromSuperview];
}

//初始化左侧导航栏
-(void)setupLeftButton{
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    //设置图片
    UIImage *imageForButton = [UIImage imageNamed:@"ic_public_tab_back"];
    [button setImage:imageForButton forState:UIControlStateNormal];
    
    button.frame = CGRectMake(0, 0, imageForButton.size.width, imageForButton.size.height);
    UIButton * btn=[[UIButton alloc] initWithFrame:CGRectMake(0, 0, 100, 44)];
    [btn addTarget:self action:@selector(popController) forControlEvents:UIControlEventTouchUpInside];
    [btn setBackgroundColor:[UIColor clearColor]];
    UIBarButtonItem *barButtonItem = [[UIBarButtonItem alloc] initWithCustomView:button ];
//    [barButtonItem setTarget:self];
//    barButtonItem.action = @selector(popController);
    self.navigationItem.leftBarButtonItem = barButtonItem;
    self.button = btn;
    [self.navigationController.navigationBar addSubview:btn];
}

-(void)popController{
    [self.navigationController popViewControllerAnimated:YES];
}

@end
